<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\HasDatabaseNotifications;


class User extends Model
{
    use Notifiable {
        notify as protected laravelNotify; 
    }

    public function notify($instance) {
        // 只有数据库类型通知才需提醒，直接发送 Email 或者其他的都 Pass
        if (method_exists($instance, 'toDatabase')) {

            $this->increment('notification_count'); 
            
        }
        $this->laravelNotify($instance); 
    }
    
    public function markAsRead() {
        $this->notification_count = 0;
        $this->save();
        $this->unreadNotifications->markAsRead(); 
    }

}
